using System.Collections.Generic;
using UnityEngine;

public class DartAssembler : MonoBehaviour
{
	public class AssembledPart
	{
		public DartPropertyType type;

		public int modelIndex;

		public GameObject model;
	}

	private List<AssembledPart> assembledParts = new List<AssembledPart>();

	public bool HasPart(DartPropertyType type, int id)
	{
		foreach (AssembledPart assembledPart in assembledParts)
		{
			if (assembledPart.type == type && assembledPart.modelIndex == id)
			{
				return true;
			}
		}
		return false;
	}

	public GameObject GetPart(DartPropertyType type)
	{
		foreach (AssembledPart assembledPart in assembledParts)
		{
			if (assembledPart.type == type)
			{
				return assembledPart.model;
			}
		}
		return null;
	}

	public void AddPart(GameObject part, DartPropertyType type, int modelIndex)
	{
		AssembledPart assembledPart = new AssembledPart();
		assembledPart.model = part;
		assembledPart.type = type;
		assembledPart.modelIndex = modelIndex;
		DartPartInit(assembledPart.model);
		assembledParts.Add(assembledPart);
	}

	public void RemovePart(DartPropertyType type)
	{
		int count = assembledParts.Count;
		for (int num = count - 1; num >= 0; num--)
		{
			if (assembledParts[num].type == type)
			{
				Object.Destroy(assembledParts[num].model);
				assembledParts.RemoveAt(num);
			}
		}
	}

	public void DartPartInit(GameObject dartPart)
	{
		Quaternion localRotation = dartPart.transform.localRotation;
		Vector3 localPosition = dartPart.transform.localPosition;
		dartPart.transform.parent = base.transform;
		dartPart.transform.localPosition = localPosition;
		dartPart.transform.localRotation = localRotation;
		float num = 1.3f;
		dartPart.transform.localScale = Vector3.one * num;
		dartPart.transform.localPosition *= num;
	}

	public void SetAlpha(float alpha)
	{
		foreach (AssembledPart assembledPart in assembledParts)
		{
			for (int i = 0; i < assembledPart.model.transform.childCount; i++)
			{
				Renderer component = assembledPart.model.transform.GetChild(i).GetComponent<Renderer>();
				if (component != null)
				{
					Material material = component.material;
					Color color = material.color;
					color.a = alpha;
					component.material.color = color;
				}
			}
		}
	}
}
